package com.itboye.jinpuyiyuan.activity.home.healthconsultation;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.adapter.HealthConsultationAdapter;
import com.itboye.jinpuyiyuan.base.BaseActivity;
import com.itboye.jinpuyiyuan.bean.ArticleListBean;
import com.itboye.jinpuyiyuan.presenter.BranchAddressPresenter;
import com.itboye.jinpuyiyuan.utils.volley.ResultEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

/**
 * Created by Administrator on 2017/12/11 0011.
 */

public class HealthConsultationActivity extends BaseActivity implements Observer {
    //title
    private ImageView leftImg,rightImg;
    private TextView leftTv,tvTitle;
    private RelativeLayout rlLeft,toobar;


    private ListView healthConsultationList;
    private HealthConsultationAdapter healthConsultationAdapter;
    private ArrayList<ArticleListBean> list;

    private BranchAddressPresenter presenter;
    private int page_index=1;
    private int page_size=10;
    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        setContentView(R.layout.activity_healthconsultation);
        initViewData();
        list=new ArrayList<>();

        presenter=new BranchAddressPresenter(this);
        presenter.queryArticle("","","published",1,10);//查询文章

        healthConsultationAdapter=new HealthConsultationAdapter(this,list);
        healthConsultationList.setAdapter(healthConsultationAdapter);
        healthConsultationList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(new Intent(HealthConsultationActivity.this,HealthConsultationDetailActivity.class));
            }
        });
    }

    private void initViewData() {
        leftTv.setVisibility(View.GONE);
        tvTitle.setText("健康资讯");
        rightImg.setVisibility(View.GONE);

    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){
            case R.id.rlLeft:
            case R.id.leftImg:
                this.finish();
                break;

        }
    }

    @Override
    public void update(Observable o, Object arg) {
        ResultEntity resultEntity = handlerError(arg);
        if (resultEntity!=null){
            if (resultEntity.getEventType()== BranchAddressPresenter.By_Post_queryByCateOrTag_success){
              List<ArticleListBean> listBeans= (List<ArticleListBean>) resultEntity.getData();
              list.addAll(listBeans);
              healthConsultationAdapter.addData(list);

            }else if (resultEntity.getEventType()== BranchAddressPresenter.By_Post_queryByCateOrTag_fail){

            }
        }
    }
}
